import React,{Component} from 'react'
import Comment from './Comment'

export default class CommentList extends Component{
    handleGetCommentIndex(index){
        if(this.props.onDelete){
            this.props.onDelete(index)
        }
    }
    render(){       
        const {comments} = this.props
        return(
            <div className={comments.length>0 ? 'commentList':''}>
                {comments.map((comment,i)=>{
                    return(
                        <Comment
                        key={i}
                        index={i}
                        comment={comment}
                        onDelete={this.handleGetCommentIndex.bind(this)}/>
                    )
                })}
            </div>
        )
    }
}